package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ServletDemo5 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPut(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置商品金额
        int money=1000;
        //截取uri片段
        String path = request.getRequestURI();
        String s = path.substring(path.lastIndexOf("/"));
        //判断
        if(s.equals("/vvip")){
            System.out.println("商品原价1000元,您享受9折优惠,优惠后金额:"+money*0.9+"元");
        }else if(s.equals("/vip")){
            System.out.println("商品原价1000元,您享受7折优惠,优惠后金额:"+money*0.7+"元");
        }else {
            System.out.println("商品原价1000元,您不享受优惠,金额:"+money+"元");
        }
    }
}
